<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Bootstrap 101 Template</title>
    <link href="../css/bootstrap.min.css" rel="stylesheet">
    <script src="../js/jquery-1.11.3.js"></script>
	<script src="../js/bootstrap.min.js"></script>
    <script src="../js/jquery.validate.js"></script>
    <style type="text/css">
     label.error{color: red;}
	</style>
    <script>
	    $(function(){
	    	$("#cakeForm").validate({
                rules:{
                  	name:{required:true},
                  	price:{required:true},
                  	stock:{required:true},
                  	mainimg:{required:true}
                },
                messages:{
	                name:{required:"名称不能为空"},
	                price:{required:"价格不能为空"},
	                stock:{required:"库存不能为空"},
	                mainimg:{required:"上传图片不能为空！"},
                }
            })
	    })
    </script>
</head>
<body>
<div class="container">
    <div class="row">
        <nav class="navbar navbar-default">
            <div class="container-fluid">
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <a class="navbar-brand" href="#">21Cake</a>
                </div>
                <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                    <ul class="nav navbar-nav">
                        <li class="active"><a href="#">首页 <span class="sr-only">(current)</span></a></li>

                        <li class="dropdown">
                            <ul class="dropdown-menu">
                                <li><a href="#">Action</a></li>
                                <li><a href="#">Another action</a></li>
                                <li><a href="#">Something else here</a></li>
                                <li role="separator" class="divider"></li>
                                <li><a href="#">Separated link</a></li>
                                <li role="separator" class="divider"></li>
                                <li><a href="#">One more separated link</a></li>
                            </ul>
                        </li>
                    </ul>
                     <form class="navbar-form navbar-left" action="cakelist.html" method="get">
                        <div class="form-group">
                        <select class="form-control" name="cid">
							<option value="0">商品分类</option>
							<c:forEach var="c" items="${clist}">
								<c:if test="${c.id==cid}">
								<option value="${c.id}" selected="selected">${c.name}</option>
								</c:if>
								<c:if test="${c.id!=cid}">
								<option value="${c.id}">${c.name}</option>
								</c:if>
							</c:forEach>
						</select>
                            <input name="title" type="text" class="form-control" placeholder="Search" value="${param.title}">
                        </div>
                        <button type="submit" class="btn btn-default">查询</button>
        
                    </form>
                    <ul class="nav navbar-nav navbar-right">
                        <li><a href="adminLogin">注销</a></li>
                        <li><a href="#">loginUser</a></li>
                        <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">用户中心<span class="caret"></span></a>
                            <ul class="dropdown-menu">
                                <li><a href="#">增加管理员</a></li>
                                <li><a href="#">修改密码</a></li>
                                <li><a href="#">修改用户名</a></li>
                                <li role="separator" class="divider"></li>
                                <li><a href="#">Separated link</a></li>
                            </ul>
                        </li>
                    </ul>
                </div>
            </div>
        </nav>
    </div>
    <div class="row">
        <div class="col-md-2">
            <ul class="list-group">
                <li class="list-group-item"><a href="orderlist.html">订单列表</a></li>
                <li class="list-group-item"><a href="userlist.jsp">用户列表</a></li>
                <li class="list-group-item"><a href="cakelist.html">商品列表</a></li>
                <li class="list-group-item"><a href="comm.html">评论列表</a></li>
            </ul>
        </div>
        <div class="col-md-10">
            <form id="cakeForm" enctype="multipart/form-data" class="form-horizontal" action="cakeEdit.html" method="post">
                <div class="form-group">
                    <label for="name" class="col-sm-2 control-label">cakeName</label>
                    <div class="col-sm-8">
                    	<input type="hidden" name="id" value="${cake.id}">
                        <input type="text" class="form-control" id="name" placeholder="cakeName" name="name" value="${cake.name}">
                    </div>
                </div>
                <div class="form-group">
                    <label for="price" class="col-sm-2 control-label">price</label>
                    <div class="col-sm-8">
                        <input name="price" type="text" class="form-control" id="price" placeholder="price" value="${cake.price}">
                    </div>
                </div>
                <div class="form-group">
                    <label for="stock" class="col-sm-2 control-label">stock</label>
                    <div class="col-sm-8">
                        <input name="stock" type="text" class="form-control" id="stock" placeholder="stock" value="${cake.stock}">
                    </div>
                </div>
                <div class="form-group">
               		<label class="col-sm-2 control-label">商品分类:</label>
                	<div class="col-sm-8">
                        <select class="form-control" name="cid">
							<c:forEach var="c" items="${clist}">
								<c:if test="${c.id==cake.id}">
								<option value="${c.id}" selected="selected">${c.name }</option>
								</c:if>
								<c:if test="${c.id!=cid}">
								<option value="${c.id}">${c.name }</option>
								</c:if>
							</c:forEach>
						</select>
					</div>
                  </div>
                <c:if test="${cake!=null }">
	                <div class="form-group">
	                    <label for="exampleInputFile" class="col-sm-2 control-label">图片</label>
	                    <div class="col-sm-8">
	                    <img src="../image/productImg/${cake.mainimg}" alt="..." style="width: 400px; higth: 400px">
	                    <input name="mainimg" type="file" id="exampleInputFile" value="${cake.mainimg}">
	                    </div>
	                </div>
                </c:if>
                <c:if test="${cake==null }">
	                <div class="form-group">
	                    <label for="exampleInputFile" class="col-sm-2 control-label">图片上传</label>
	                    <div class="col-sm-8">
	                    <input name="mainimg" type="file" id="exampleInputFile">
	                    </div>
	                </div>
                </c:if>               
                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-8">
                        <button type="submit" class="btn btn-default">保存</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

</body>
</html>
